import datetime
import random

from info import db
from info.models import User
from manage import app


def add_test_user():
    users = []
    now = datetime.datetime.now()
    for num in range(0,10000):
        try:
            user = User()
            user.nick_name = '%011d'%num
            user.mobile = '%011d'%num
            user.password_hash ='pbkdf2:sha256:150000$rSXHEKwt$a2792dc9a9c62bffd89af54e61d2bd359f0bfa72cdd6319508278ea8b1996b5f'
            user.last_login = now - datetime.timedelta(seconds=random.randint(0,2678400))
            users.append(user)
        except Exception as e:
            print(e)

    with app.app_context():
        db.session.add_all(users)
        db.session.commit()

if __name__ == '__main__':
    add_test_user()

